package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo9 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection();) {
            connection.setAutoCommit(false);
            String sql = "UPDATE user "+
                         "SET password=?,nickname=?,age=? "+
                         "WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"123456");
            ps.setString(2,"张三");
            ps.setInt(3,20);
            ps.setInt(4,2);
            int count = ps.executeUpdate();
            System.out.println(count>0? "修改成功":"修改失败");

            connection.commit();
            System.out.println("事务提交了,修改算数了");



        }catch(SQLException e){
            e.printStackTrace();
        }
    }
}
